//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using EntLibContrib.Resource;
using EntLibContrib.Resource.Configuration.Design;

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif

namespace EntLibContrib.Resource.Configuration.Design.Tests
{
	[TestClass]
	public class ResourceManagerSettingsNodeFixture : ConfigurationDesignHost
	{
		private DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();
		private static ResourceManager internalResources = InternalResourceFactory.GetResourceManager();

		protected override void InitializeCore ()
		{
			SetDictionaryConfigurationSource(configurationSource);
		}

		[TestMethod]
		public void EnsureResourceManagerSettingsNodePropertyCategoriesAndDescriptions ()
		{
			Assert.IsTrue(ResourceAttributesHelper.AssertResourceDescription(typeof(ResourceManagerSettingsNode), "DefaultResourceManager", internalResources["DefaultResourceManagerDescription"]));
			Assert.IsTrue(ResourceAttributesHelper.AssertResourceCategory(typeof(ResourceManagerSettingsNode), "DefaultResourceManager", internalResources["CategoryGeneral"]));
		}

		[TestMethod]
		public void ResourceManagerSettingsNodeTest ()
		{
			ResourceManagerNode defaultResourceManager = new ResourceManagerNode();
			ApplicationNode.AddNode(defaultResourceManager);
			defaultResourceManager.Name = "testName";

			ResourceManagerSettingsNode node = new ResourceManagerSettingsNode();
			ApplicationNode.AddNode(node);
			Assert.AreEqual("Resource Application Block", node.Name);

			node.DefaultResourceManager = defaultResourceManager;
			Assert.AreEqual(defaultResourceManager, node.DefaultResourceManager);
		}

		[TestMethod]
		[ExpectedException(typeof(InvalidOperationException))]
		public void MakeSureThatYouCanOnlyAddOneResourceManagerCollectionNode ()
		{
			ResourceManagerNode defaultResourceManager = new ResourceManagerNode();
			ApplicationNode.AddNode(defaultResourceManager);
			defaultResourceManager.Name = "testName";

			ResourceManagerSettingsNode node = new ResourceManagerSettingsNode();
			ApplicationNode.AddNode(node);
			ResourceManagerCollectionNode collectionNode = new ResourceManagerCollectionNode();
			node.AddNode(collectionNode);
			node.AddNode(new ResourceManagerCollectionNode());
		}
	}
}
